<?php
namespace Home\Controller;
use Think\Controller;
class ListController extends HomeController {
    public function lst($catName,$pageSize = 2){
        /***********************获取分类文章*************************/
        //获取分类ID
        $catModel = D('Admin/Category');
        $catId = $catModel->field('id')
            ->where([
                'name' =>['eq',$catName]
            ])->find();
        //获取文章列表
        if($catId) {
            $articleModel = D('Admin/Article');
            $count= $articleModel
                ->where([
                    'cat_id' => ['in', $catId]
                ])
                ->count();
            $page = new \Think\Page($count, $pageSize);
            // 配置翻页的样式
            $page->setConfig('prev', '上一页');
            $page->setConfig('next', '下一页');
            $data['page'] = $page->show();
            $data['data'] = $articleModel->field('id,title,create_time,pic')
                ->where([
                    'cat_id' => ['in', $catId]
                ])
                ->order(' create_time desc')
                ->limit($page->firstRow.','.$page->listRows)
                ->select();



            $this->assign(array(
                'data' => $data['data'],
                'page' => $data['page'],
            ));
        }
        $this->assign('catName', $catName);
        $this->display();


        /************************************* 翻页 ****************************************/

    }
}